package wiki.liven.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wiki.liven.pojo.bean.User;
import wiki.liven.pojo.dto.ReturnJosn;
import wiki.liven.service.IUserService;

import java.util.List;

/**
 * Created by qiangjun on 2017/2/21.
 * URI的定义可参照
 * 石墨文档https://shimo.im/doc/ILkrn45yXakpErQG
 * @CrossOrigin注解为Spring boot的跨域处理方式
 * 具体可以参阅BLOG
 * http://blog.csdn.net/isea533/article/details/50449907
 */
@RestController
@RequestMapping("users")
@CrossOrigin()
public class UserController {


    @Autowired
    private IUserService service;

    @ApiOperation(value="获取指定用户的信息",notes = "根据用户ID获取用户实体")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),})
    @GetMapping(value = "/{id}")
    public ReturnJosn getTheUser(@PathVariable(value = "id") Long id){
        User user = service.selectById(id);
        ReturnJosn returnJosn = new ReturnJosn();
        returnJosn.setCode("200");
        returnJosn.setData(user);
        return returnJosn;
    }


    @ApiOperation(value="获取所有用户的信息")
    @GetMapping(value = "")
    public ReturnJosn getAllUsers(){
        List<User> users = null;
        ReturnJosn returnJosn = new ReturnJosn();
        returnJosn.setCode("200");
        returnJosn.setData(users);
        return returnJosn;
    }




}
